/*
*  SkyOpenALListener.cpp
*  
*
*  Created by Alexander Trutchenko on 11/02/12.
*  Copyright 2012 Free Team. All rights reserved.
*
*/

#include "SkyOpenALListener.h"

#include "SkyOpenALInclude.h"

namespace sky {

////////////////////////////////////////////////////////
//
/** SkyOpenALListener
*  
*/
////////////////////////////////////////////////////////

SkyOpenALListener::SkyOpenALListener()
{
	SkyVector3D orientation[2];
	alGetListenerfv(AL_ORIENTATION, orientation[0]);
	_atDirection = orientation[0];
	_upDirection = orientation[1];
	alGetListenerfv(AL_POSITION, _position);
	alGetListenerfv(AL_VELOCITY, _velocity);

		// Position of the Listener.
	ALfloat ListenerPos[] = { 0.0, 0.0, 0.0 };

	// Velocity of the Listener.
	ALfloat ListenerVel[] = { 0.0, 0.0, 0.0 };

	// Orientation of the Listener. (first 3 elements are "at", second 3 are "up")
	// Also note that these should be units of '1'.
	ALfloat ListenerOri[] = { 0.0, 0.0, -1.0,  0.0, 1.0, 0.0 };

		// Set listener properties
    alListenerfv(AL_POSITION,    ListenerPos);
    alListenerfv(AL_VELOCITY,    ListenerVel);
    alListenerfv(AL_ORIENTATION, ListenerOri);
}

void SkyOpenALListener::setPosition(const SkyVector3D& position)
{
	_position = position;
	alListenerfv(AL_POSITION, _position);
}

void SkyOpenALListener::moveBy(const SkyVector3D& deltaPos)
{
	_position += deltaPos;
	alListenerfv(AL_POSITION, _position);
}

void SkyOpenALListener::setVelocity(const SkyVector3D& velocity)
{
	_velocity = velocity;
	alListenerfv(AL_VELOCITY, _velocity);
}
void SkyOpenALListener::setOrientation(const SkyVector3D& at, const SkyVector3D& up)
{
	_atDirection = at;
	_upDirection = up;
	SkyVector3D orientation[] = { at, up };
	alListenerfv(AL_ORIENTATION, orientation[0]);
}
void SkyOpenALListener::orientation(SkyVector3D* at_up) const
{
	at_up[0] = _atDirection;
	at_up[1] = _upDirection;
}
void SkyOpenALListener::setOrientation(const SkyVector3D* at_up)
{
	alListenerfv(AL_ORIENTATION, *at_up);
}


} // namespace sky
